<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="导入批次号" prop="batchNo">
        <el-input
          v-model="queryParams.batchNo"
          placeholder="请输入导入批次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="样本框编码" prop="sampleboxCode">
        <el-input
          v-model="queryParams.sampleboxCode"
          placeholder="请输入样本框编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="sampleboxName">
        <el-input
          v-model="queryParams.sampleboxName"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理状态" prop="processStatus">
        <el-select v-model="queryParams.processStatus" placeholder="请选择处理状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_common_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['erecord:sampleboxImportDetail:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['erecord:sampleboxImportDetail:edit']"
        >修改</el-button>
      </el-col>
      -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['erecord:sampleboxImportDetail:remove']"
        >删除</el-button>
      </el-col>
      <!--
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['erecord:sampleboxImportDetail:export']"
        >导出</el-button>
      </el-col>
      -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sampleboxImportDetailList" @selection-change="handleSelectionChange" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column align="center" label="序号" width="55">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="id" align="center" prop="id" v-if="false" width="100"/>
      <el-table-column label="导入批次号" align="center" prop="batchNo" width="100"/>
      <el-table-column label="样本框编码" align="center" prop="sampleboxCode" width="100"/>
      <el-table-column label="名称" align="center" prop="sampleboxName" width="100"/>
      <el-table-column label="样本框类型" align="center" prop="sampleboxTypeImport" width="100"/>

      <el-table-column label="所属区域名称" align="center" prop="regionName" width="100"/>

      <el-table-column label="所属街道名称" align="center" prop="streetName" width="100"/>

      <el-table-column label="所属社区名称" align="center" prop="communityName" width="100"/>

      <el-table-column label="所属街区名称" align="center" prop="blockName" width="100"/>
      <el-table-column label="经度" align="center" prop="longitude" width="100"/>
      <el-table-column label="纬度" align="center" prop="latitude" width="100"/>
      <el-table-column label="详细地址" align="center" prop="detailedAddress" width="200"/>
      <el-table-column label="参考地址" align="center" prop="referenceAddress" width="200"/>
      <el-table-column label="责任单位" align="center" prop="accountabilityUnit" width="100"/>
      <el-table-column label="负责企业" align="center" prop="responsibleEnterprise" width="100"/>
      <el-table-column label="标段名称" align="center" prop="sectionName" width="100"/>
      <el-table-column label="主管单位" align="center" prop="competentOrganization" width="100"/>
      <el-table-column label="监管单位" align="center" prop="supervisoryUnit" width="100"/>
      <el-table-column label="设施状态" align="center" prop="facilityStatus" width="100"/>
      <el-table-column label="住宅小区类别" align="center" prop="residentialClass" width="100"/>
      <el-table-column label="备注说明" align="center" prop="remark" width="100"/>
      <el-table-column label="所在行业" align="center" prop="industry" width="100"/>
      <el-table-column label="维护开始时间" align="center" prop="maintenanceStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.maintenanceStartTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="维护结束时间" align="center" prop="maintenanceEndTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.maintenanceEndTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="负责人" align="center" prop="principal" width="100"/>
      <el-table-column label="片区主管" align="center" prop="districtSupervisor" width="100"/>

      <el-table-column label="城市管家负责人" align="center" prop="cityPrincipalImport" width="140"/>
      <el-table-column label="城市管家负责人手机号码" align="center" prop="cityPrincipalPhone" width="100"/>

      <el-table-column label="城市管家" align="center" prop="cityStewardImport" width="100"/>
      <el-table-column label="城市管家手机号码" align="center" prop="cityStewardPhone" width="140" />
      <el-table-column label="所属等级" align="center" prop="grade" width="100"/>

      <el-table-column label="处理状态" align="center" prop="processStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_status" :value="scope.row.processStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="处理信息" align="center" prop="processMsg" width="200"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updateBy" />
      <!--
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['erecord:sampleboxImportDetail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['erecord:sampleboxImportDetail:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
      -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改导入明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="导入批次号" prop="batchNo">
          <el-input v-model="form.batchNo" placeholder="请输入导入批次号" />
        </el-form-item>
        <el-form-item label="样本框编码" prop="sampleboxCode">
          <el-input v-model="form.sampleboxCode" placeholder="请输入样本框编码" />
        </el-form-item>
        <el-form-item label="名称" prop="sampleboxName">
          <el-input v-model="form.sampleboxName" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="样本框类型-import" prop="sampleboxTypeImport">
          <el-input v-model="form.sampleboxTypeImport" placeholder="请输入样本框类型-import" />
        </el-form-item>
        <el-form-item label="所属区域" prop="region">
          <el-input v-model="form.region" placeholder="请输入所属区域" />
        </el-form-item>
        <el-form-item label="所属区域名称" prop="regionName">
          <el-input v-model="form.regionName" placeholder="请输入所属区域名称" />
        </el-form-item>
        <el-form-item label="所属街道" prop="street">
          <el-input v-model="form.street" placeholder="请输入所属街道" />
        </el-form-item>
        <el-form-item label="所属街道名称" prop="streetName">
          <el-input v-model="form.streetName" placeholder="请输入所属街道名称" />
        </el-form-item>
        <el-form-item label="所属社区" prop="community">
          <el-input v-model="form.community" placeholder="请输入所属社区" />
        </el-form-item>
        <el-form-item label="所属社区名称" prop="communityName">
          <el-input v-model="form.communityName" placeholder="请输入所属社区名称" />
        </el-form-item>
        <el-form-item label="所属街区" prop="block">
          <el-input v-model="form.block" placeholder="请输入所属街区" />
        </el-form-item>
        <el-form-item label="所属街区名称" prop="blockName">
          <el-input v-model="form.blockName" placeholder="请输入所属街区名称" />
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="详细地址" prop="detailedAddress">
          <el-input v-model="form.detailedAddress" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="参考地址" prop="referenceAddress">
          <el-input v-model="form.referenceAddress" placeholder="请输入参考地址" />
        </el-form-item>
        <el-form-item label="责任单位" prop="accountabilityUnit">
          <el-input v-model="form.accountabilityUnit" placeholder="请输入责任单位" />
        </el-form-item>
        <el-form-item label="负责企业" prop="responsibleEnterprise">
          <el-input v-model="form.responsibleEnterprise" placeholder="请输入负责企业" />
        </el-form-item>
        <el-form-item label="标段名称" prop="sectionName">
          <el-input v-model="form.sectionName" placeholder="请输入标段名称" />
        </el-form-item>
        <el-form-item label="主管单位" prop="competentOrganization">
          <el-input v-model="form.competentOrganization" placeholder="请输入主管单位" />
        </el-form-item>
        <el-form-item label="监管单位" prop="supervisoryUnit">
          <el-input v-model="form.supervisoryUnit" placeholder="请输入监管单位" />
        </el-form-item>
        <el-form-item label="住宅小区类别" prop="residentialClass">
          <el-input v-model="form.residentialClass" placeholder="请输入住宅小区类别" />
        </el-form-item>
        <el-form-item label="备注说明" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所在行业" prop="industry">
          <el-input v-model="form.industry" placeholder="请输入所在行业" />
        </el-form-item>
        <el-form-item label="维护开始时间" prop="maintenanceStartTime">
          <el-date-picker clearable
            v-model="form.maintenanceStartTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择维护开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="维护结束时间" prop="maintenanceEndTime">
          <el-date-picker clearable
            v-model="form.maintenanceEndTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择维护结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="负责人" prop="principal">
          <el-input v-model="form.principal" placeholder="请输入负责人" />
        </el-form-item>
        <el-form-item label="片区主管" prop="districtSupervisor">
          <el-input v-model="form.districtSupervisor" placeholder="请输入片区主管" />
        </el-form-item>
        <el-form-item label="城市管家负责人" prop="cityPrincipal">
          <el-input v-model="form.cityPrincipal" placeholder="请输入城市管家负责人" />
        </el-form-item>
        <el-form-item label="城市管家负责人-import" prop="cityPrincipalImport">
          <el-input v-model="form.cityPrincipalImport" placeholder="请输入城市管家负责人-import" />
        </el-form-item>
        <el-form-item label="城市管家负责人手机号码" prop="cityPrincipalPhone">
          <el-input v-model="form.cityPrincipalPhone" placeholder="请输入城市管家负责人手机号码" />
        </el-form-item>
        <el-form-item label="城市管家" prop="citySteward">
          <el-input v-model="form.citySteward" placeholder="请输入城市管家" />
        </el-form-item>
        <el-form-item label="城市管家-import" prop="cityStewardImport">
          <el-input v-model="form.cityStewardImport" placeholder="请输入城市管家-import" />
        </el-form-item>
        <el-form-item label="城市管家手机号码" prop="cityStewardPhone">
          <el-input v-model="form.cityStewardPhone" placeholder="请输入城市管家手机号码" />
        </el-form-item>
        <el-form-item label="所属等级" prop="grade">
          <el-input v-model="form.grade" placeholder="请输入所属等级" />
        </el-form-item>
        <el-form-item label="要求" prop="askFor">
          <el-input v-model="form.askFor" placeholder="请输入要求" />
        </el-form-item>
        <el-form-item label="要求-import" prop="askForImport">
          <el-input v-model="form.askForImport" placeholder="请输入要求-import" />
        </el-form-item>
        <el-form-item label="巡检地点范围" prop="inspectionSiteArea">
          <el-input v-model="form.inspectionSiteArea" placeholder="请输入巡检地点范围" />
        </el-form-item>
        <el-form-item label="处理状态" prop="processStatus">
          <el-select v-model="form.processStatus" placeholder="请选择处理状态">
            <el-option
              v-for="dict in dict.type.sys_common_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="处理信息" prop="processMsg">
          <el-input v-model="form.processMsg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSampleboxImportDetail, getSampleboxImportDetail, delSampleboxImportDetail, addSampleboxImportDetail, updateSampleboxImportDetail } from "@/api/erecord/sampleboxImportDetail";

export default {
  name: "SampleboxImportDetail",
  dicts: ['sys_common_status'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 导入明细表格数据
      sampleboxImportDetailList: [],
      // 弹出层标题
      title: "",
      // 是否新增
      isAdd : true,      
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        batchNo: undefined,
        sampleboxCode: undefined,
        sampleboxName: undefined,
        processStatus: undefined,
        orderByColumn: "update_time,sampleboxCode",
        isAsc: "desc,asc",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        batchNo: [
          { required: true, message: "导入批次号不能为空", trigger: "blur" }
        ],
        sampleboxCode: [
          { required: true, message: "样本框编码不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    const batchNo = this.$route.params && this.$route.params.batchNo;
    //console.log("--------------------------  " , batchNo)
    if (batchNo) {
      this.queryParams.batchNo = batchNo;
      //this.form.batchNo = batchNo;
    }    
    this.getList();
  },
  methods: {
    /** 查询导入明细列表 */
    getList() {
      this.loading = true;
      listSampleboxImportDetail(this.queryParams).then(response => {
        this.sampleboxImportDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        batchNo: undefined,
        sampleboxCode: undefined,
        sampleboxName: undefined,
        sampleboxType: undefined,
        sampleboxTypeImport: undefined,
        region: undefined,
        regionName: undefined,
        street: undefined,
        streetName: undefined,
        community: undefined,
        communityName: undefined,
        block: undefined,
        blockName: undefined,
        longitude: undefined,
        latitude: undefined,
        detailedAddress: undefined,
        referenceAddress: undefined,
        accountabilityUnit: undefined,
        responsibleEnterprise: undefined,
        sectionName: undefined,
        competentOrganization: undefined,
        supervisoryUnit: undefined,
        facilityStatus: undefined,
        residentialClass: undefined,
        remark: undefined,
        industry: undefined,
        maintenanceStartTime: undefined,
        maintenanceEndTime: undefined,
        principal: undefined,
        districtSupervisor: undefined,
        cityPrincipal: undefined,
        cityPrincipalImport: undefined,
        cityPrincipalPhone: undefined,
        citySteward: undefined,
        cityStewardImport: undefined,
        cityStewardPhone: undefined,
        grade: undefined,
        askFor: undefined,
        askForImport: undefined,
        inspectionSiteArea: undefined,
        processStatus: undefined,
        processMsg: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        delFlag: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.isAdd = true;
      this.title = "添加导入明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getSampleboxImportDetail(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.isAdd = false;
        this.title = "修改导入明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.isAdd == false) {
            updateSampleboxImportDetail(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addSampleboxImportDetail(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据').then(() => {
        this.loading = true;
        return delSampleboxImportDetail(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('erecord/sampleboxImportDetail/export', {
        ...this.queryParams
      }, `sampleboxImportDetail_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
